package org.tio.sitexxx.web.server.controller.gl;

import com.jfinal.plugin.activerecord.Page;
import org.tio.http.server.annotation.RequestPath;
import org.tio.sitexxx.service.model.main.Promoter;
import org.tio.sitexxx.service.service.gl.PromoterManageService;
import org.tio.utils.crypto.Md5;
import org.tio.utils.resp.Resp;

/**
 * 推广者管理
 */
@RequestPath("/gl/manage/promoter")
public class PromoterManage {
    public PromoterManageService promoterManageService = PromoterManageService.me;

    /**
     * 推广者列表
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @RequestPath("/promoter-list")
    public Resp promoterList(int pageNumber,int pageSize){
        Page<Promoter> promoterPage = promoterManageService.promoterList(pageNumber,pageSize);
        if(promoterPage==null||promoterPage.getList().size()==0)
            return Resp.fail();
        return Resp.ok(promoterPage);
    }

    /**
     * 修改密码
     * @param id
     * @param password
     * @return
     */
    @RequestPath("/update/password")
    public Resp updatePassword(int id,String password){
        boolean result = Promoter.dao.findById(id).set("password", Md5.getMD5(password)).update();
        if(!result)
            return Resp.fail();
        return Resp.ok();
    }
}
